﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Telerik.Web.Mvc;
using Helena.Areas.Campanas.Models;
using Helena.Areas.Vendedores.Models;

namespace Helena.Areas.Campanas.Controllers
{
    public class CampanaController : Controller
    {
        LogicaCampana db = new LogicaCampana();
        LogicaVendedor vd = new LogicaVendedor();

        

        public ActionResult Index()
        {
            VendedorView vw = (VendedorView)Session["Vendedor"];
            if (vw.ID!=0)
            {
                return View();
            }
            else
            {
                return Redirect("../Home/NoSession");
            }
            
        }

        [GridAction]
        public ActionResult Select()
        {
            return View("Index", new GridModel(db.i_RetornarCampanas()));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult Insert()
        {

            CampanaView c_v = new CampanaView();
            if (TryUpdateModel(c_v))
            {
                db.i_AgregarCampana(c_v);
            }
            return View("Index", new GridModel(db.i_RetornarCampanas()));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult Delete(int? id)
        {
            int ID = id ?? -1;
            db.i_EliminarCampana(ID);
            return View("Index", new GridModel(db.i_RetornarCampanas()));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult Update(CampanaView c)
        {
            db.i_ModificarCampana(c);
            return View("Index", new GridModel(db.i_RetornarCampanas()));
        }

    }
}
